export function tabPosition(domList, domHeightList = [], tabHeight = 0, tabOffSet) {

  var FONT_SIZE = parseFloat(document.documentElement.style.fontSize || 20)
  var tabOffSet = $('#tab').offset().top || tabOffSet

  for (var i = 0; i < domList.length; i++) {
    domHeightList.push($(domList[i]).offset().top)
  }

  $(document).scroll(function () {
    var scrollTop = $(document).scrollTop()
    if (scrollTop >= tabOffSet) {
      if (location.pathname.indexOf('2020semlxgh') > 0 && document.documentElement.clientWidth <= 979) {
        $('#tab').removeClass('tab-fixed')
        $('#tab-box').css('display', 'none')
      } else {
        $('#tab').addClass('tab-fixed')
        $('#tab-box').css('display', 'block')
      }

      var current = 0,
        currentTab = 0
      scrollTop += tabHeight

      for (var i = 0; i < domHeightList.length; i++) {
        if (scrollTop > domHeightList[i]) current = i + 1
      }

      current--

      // 当前栏位显示自己，不用切换到下一栏位
      currentTab =
        current < 0 ?
        0 :
        current >= domHeightList.length ?
        domHeightList.length - 1 :
        current

        if (document.documentElement.clientWidth <= 979 && location.pathname.indexOf('semriben') > 0) {
				currentTab = currentTab > 3 ? 5 : currentTab
      }
      // 美英
      if(document.documentElement.clientWidth > 979 && location.pathname.indexOf('2021offerAE') > 0 ) {
			if (
				currentTab === 5 &&
				scrollTop - $('.section7').offset().top < 0 &&
				scrollTop - $('.section7').offset().top > -15 * FONT_SIZE
			) {
				currentTab = 6
			}
      }
      
      $('#tab')
        .find('div:eq(' + currentTab + ')')
        .addClass('tab-list-active')
        .siblings()
        .removeClass('tab-list-active')
    } else {
      $('#tab').removeClass('tab-fixed')
      $('#tab-box').css('display', 'none')
    }
  })

  $('.tab-list').on('click', function () {
    var index = $('.tab').find('.tab-list').index($(this).closest('.tab-list'))
    // semriben
    if(location.pathname.indexOf('semriben') > 0) {
      index = index >= 4 ? 4 : index
    }
    if (navigator.userAgent.indexOf('Trident') > 0) {
      document.body.scrollTop = document.documentElement.scrollTop =
        domHeightList[index] - tabHeight + FONT_SIZE
    } else {
      window.scroll({
        top: domHeightList[index] - tabHeight + FONT_SIZE,
        behavior: 'smooth'
      })
    }
  })
}